package com.mew.chess.core.game.lh.game.message;

import com.zebra.common.ZebraBaseMessage;
import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


@Data
@ToString
@NoArgsConstructor
public class LhPaymentMessage extends ZebraBaseMessage<LhPaymentMessage> {

    private HashMap<Integer,Long> paymentMap = new HashMap<>(); //negative lose; positive win

    private LhHistoryMessage historyMessage = new LhHistoryMessage();

    private long paymentNumber = -1; //当前赔付金额 （-1表示没有参与本局）
    private long goldNumber; //current user goldNumber

    private List<LhUserMessage> bigRList = new ArrayList<>();

    @Override
    public void write(ByteBuf b) {

        writeMsg(b);
    }

    public void writeMsg(ByteBuf b) {
        writeInt(b, paymentMap.size());
        for (Integer type : paymentMap.keySet()) {
            writeLongArray(b,new long[]{type,paymentMap.get(type)});
        }

        historyMessage.writeMsg(b);
        writeLong(b,paymentNumber);
        writeLong(b,goldNumber);
        writeInt(b,bigRList.size());
        for (LhUserMessage message : bigRList) {
            message.write(b);
        }
    }

    @Override
    public LhPaymentMessage read(ByteBuf b) {
        return null;
    }

    public void clearInfo(){
        paymentMap.clear();
    }


}
